package com.usian.wemedia.controller.v1;

import com.usian.apis.wemedia.WmMaterialControllerApi;
import com.usian.common.constant.material.CollectConstants;
import com.usian.common.fastdfs.FastDFSClient;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.model.media.pojos.WmMaterial;
import com.usian.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;

/**
 * ClassName: WmmediaMaterialController
 * Author:   WGG
 * Date:    2022-11-2022/11/16-11:53
 * Version: 1.0
 * Description:
 */
@RestController
@RequestMapping("/wemedia/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {

    @Autowired
    private WmMaterialService wmMaterialService;
    /**
     * 图片上传
     * @param multipartFile
     * @return
     */
    @Override
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {

        return wmMaterialService.uploadPicture(multipartFile);
    }


    /**
     * 图片的分页查询
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.list(dto);
    }

    @Override
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable Integer id) {
        return wmMaterialService.delPicture(id);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @Override
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable Integer id) {
        return wmMaterialService.collectOrCancelCollect(id, CollectConstants.TYPE_CANCEL_COLLECT);
    }

    /**
     * 收藏
     * @param id
     * @return
     */
    @Override
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id) {
        return wmMaterialService.collectOrCancelCollect(id,CollectConstants.TYPE_COLLECT);
    }
}
